package com.younion.action.manage;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.common.collect.Maps;
import com.younion.common.base.BaseAction;
import com.younion.common.paginator.Paginator;

import cpcns.jhsks.util.MapCollectionUtils;

import com.younion.business.IMemberCardService;
import com.younion.business.IRechargeFeedbackTaskLogService;
import com.younion.vo.RechargeFeedbackTaskLogVO;

/**
 * @author Joe Chen
*/
public class RechargeFeedbackTaskLogAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	protected static final Log logger = LogFactory.getLog(RechargeFeedbackTaskLogAction.class);

	private IRechargeFeedbackTaskLogService rechargeFeedbackTaskLogService = null;

	private RechargeFeedbackTaskLogVO rechargeFeedbackTaskLogVO = new RechargeFeedbackTaskLogVO();

	private List<RechargeFeedbackTaskLogVO> rechargeFeedbackTaskLogList;// 结果集列表
	
	private Collection membercards = null;
	
	@Autowired
	private IMemberCardService memberCardService = null;
	
	/**
	 * 列表：翻页区；数据区
	 */
	@SuppressWarnings("unchecked")
	public String listRechargeFeedbackTaskLog() {
		try {
			Map paramMap = null;
			if (rechargeFeedbackTaskLogVO != null) {
				paramMap = MapCollectionUtils.removeEmptyEntry(PropertyUtils.describe(rechargeFeedbackTaskLogVO));
			}
			// 获取总记录数
			int total = rechargeFeedbackTaskLogService.getCountByMap(paramMap);
			// 根据总记录数获取分页对象
			Paginator paginator = this.getPaginator(total);
			rechargeFeedbackTaskLogList = rechargeFeedbackTaskLogService.get(paramMap, paginator);
			// 保存分页对象
			this.savaPaginator(paginator);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return SUCCESS;
	}

	/**
	 * 新增
	 */
	public String addRechargeFeedbackTaskLog() {
		return SUCCESS;
	}

	/**
	 * 修改保存，调度Jsp
	 */
	public String editRechargeFeedbackTaskLog() {
		try {
			rechargeFeedbackTaskLogVO = rechargeFeedbackTaskLogService.getById(rechargeFeedbackTaskLogVO.getId().toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/**
	 * 保存动作
	 */
	public String saveRechargeFeedbackTaskLog() {
		try {
			rechargeFeedbackTaskLogVO = rechargeFeedbackTaskLogService.save(rechargeFeedbackTaskLogVO);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/**
	 * 删除
	 */
	public String deleteRechargeFeedbackTaskLog() {
		try {
			String pkId = request.getParameter("key");
			rechargeFeedbackTaskLogService.remove(Arrays.asList(pkId.split(",")));
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
		return SUCCESS;
	}
	/**
	 * 查看鿴
	 */
	public String viewRechargeFeedbackTaskLog() {
		try {
			String pkId = request.getParameter("key"); 
			rechargeFeedbackTaskLogVO = rechargeFeedbackTaskLogService.getById(pkId);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
		return SUCCESS;

	}

	public RechargeFeedbackTaskLogVO getRechargeFeedbackTaskLogVO() {
		return rechargeFeedbackTaskLogVO;
	}

	public void setRechargeFeedbackTaskLogVO(RechargeFeedbackTaskLogVO rechargeFeedbackTaskLogVO) {
		this.rechargeFeedbackTaskLogVO = rechargeFeedbackTaskLogVO;
	}

	public void setRechargeFeedbackTaskLogService(IRechargeFeedbackTaskLogService rechargeFeedbackTaskLogService) {
		this.rechargeFeedbackTaskLogService = rechargeFeedbackTaskLogService;
	}

	public List<RechargeFeedbackTaskLogVO> getRechargeFeedbackTaskLogList() {
		return rechargeFeedbackTaskLogList;
	}

	public void setRechargeFeedbackTaskLogList(List<RechargeFeedbackTaskLogVO> rechargeFeedbackTaskLogList) {
		this.rechargeFeedbackTaskLogList = rechargeFeedbackTaskLogList;
	}

	public IRechargeFeedbackTaskLogService getRechargeFeedbackTaskLogService() {
		return rechargeFeedbackTaskLogService;
	}
	
	public Collection getMembercards() {
		if(membercards == null){
			try {
				if(this.getSessionUser().getCustomer() == null){
					membercards = memberCardService.getAll();
				}else{
					Map paramMap = Maps.newHashMap();
					paramMap.put("customerId",this.getSessionUser().getCustomer().getId());
					membercards = memberCardService.getByMap(paramMap);
				}
			} catch (Exception e) {
			}
		}
		return membercards;
	}

	public void setMembercards(Collection membercards) {
		this.membercards = membercards;
	}

	public IMemberCardService getMemberCardService() {
		return memberCardService;
	}

	public void setMemberCardService(IMemberCardService memberCardService) {
		this.memberCardService = memberCardService;
	}
	
}